layui.define(["table", "form", "admin", "upload"], function (exports) {
  var $ = layui.$,
    table = layui.table,
    form = layui.form,
    upload = layui.upload,
    admin = layui.admin;

  table.render({
    elem: "#LAY-live-manage",
    url: "/admin/live/preview_handle",
    cols: [
      [
        { field: "created_at", title: "创建时间", width: 170, fixed: "left" },
        { field: "match_id", title: "比赛ID", width: 150 },
        { field: "comp_title", title: "赛事名称", width: 150 },
        {
          field: "", title: "主队-客队", width: 200, templet: function (d) {
            return d.home + '-' + d.away;
          },
        },
        {
          field: "sport_id", title: "直播类型", width: 130, templet: function (d) {
            if (d.sport_id == 1) {
              return '足球'
            }
            if (d.sport_id == 2) {
              return '蓝球'
            }
            if (d.sport_id == 5) {
              return '其它'
            }
          },
        },
        { field: "anchors", title: "主播", width: 300 },
        { field: "date", title: "比赛时间", width: 170 },
        {
          title: "操作",
          width: 200,
          align: "center",
          fixed: "right",
          toolbar: "#table-livelist-live",
        },
      ],
    ],
    page: true,
    limit: 20,
    height: "full-140",
    text: "对不起，加载出现异常！",
    even: true,
  });

  //监听工具条
  table.on("tool(LAY-live-manage)", function (obj) {

    if (obj.event === "edit" && obj.data.is_custom == 1) {
      layer.open({
        type: 2,
        title: "编辑修改直播预告",
        content: "/admin/live/preview_custom_edit?id=" + obj.data.id,
        maxmin: true,
        area: ['100%', '100%'], // 100%全屏
      });
    } else {
      layer.open({
        type: 2,
        title: "编辑修改直播预告",
        content: "/admin/live/preview_edit?id=" + obj.data.id,
        maxmin: true,
        area: ["800px", "600px"],
      });
    }

    if (obj.event == "delete") {
      layer.confirm("确定要删除此场预告吗？", { icon: 6 }, function () {
        $.ajax({
          type: "POST", //请求方式
          url: "/admin/live/preview_del", //请求地址
          dataType: "json", //返回的数据类型
          data: { id: obj.data.id }, //数据
          //请求成功
          success: function (data) {
            if (data.code == 0) {
              layer.msg(data.msg, { icon: 1, time: 1000 }, function () {
              });
              table.reload("LAY-live-manage");
            } else {
              layer.msg(data.msg, { icon: 2, time: 1000 });
            }
          },
        });
      });
    }
  });
  exports("live_preview", {});
});
